package com.yiya.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yiya.bean.District;
import com.yiya.mapper.DistrictMapper;
import com.yiya.model.DistrictModel;

@Service("districtService")
public class DistrictService{
	@Autowired
	private DistrictMapper districtMapper;

	public List<District> queryByList(DistrictModel bean) {
		Integer rowCount = queryByCount(bean);
		bean.getPager().setRowCount(rowCount);
		List<District> bills = districtMapper.selectByModel(bean);
		return bills;
	}

	public int queryByCount(DistrictModel bean) {
		return districtMapper.countByModel(bean);
	}
	
	public int add(District district){
		return districtMapper.insert(district);
	}
	
	public int Update(District district){
		return districtMapper.updateByPrimaryKeySelective(district);
	}
	
	public District queryByCode(Integer code){
		return districtMapper.selectByPrimaryKey(code);
	}
	
	public void delete(Integer[] ids){
		for(Integer id:ids){
			District district = districtMapper.selectByPrimaryKey(id);
			district.setDelFlag(1);
			districtMapper.updateByPrimaryKeySelective(district);
		}
	}
	
	/**
	 * 根据上级行政区划代码查找地区
	 * @param model
	 * @return
	 */
	public List<District> getDistrict(DistrictModel model){
		return districtMapper.selectDistrict(model);
	}
	
	
}
